package com.jic.order.impl;

import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.order.entity.OrderRefund;
import com.jic.order.manage.request.OrderRefundRequest;
import com.jic.order.manage.response.OrderRefundResponse;
import com.jic.order.mapper.OrderRefundMapper;
import com.jic.order.service.OrderRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 退款明细表
 * @author :
 * @email :
 * @since : 2020-03-06 05:31:40
 * @version : v1.0.0
 */
@Service
public class OrderRefundServiceImpl implements OrderRefundService {

    @Autowired
    private OrderRefundMapper orderRefundMapper;

    @Override
    public long insert(OrderRefund orderRefund) {
        long flag = orderRefundMapper.insert(orderRefund);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return orderRefundMapper.delete(id);
    }

    @Override
    public long update(OrderRefund orderRefund) {
        return orderRefundMapper.update(orderRefund);
    }

    @Override
    public OrderRefund queryByPrimaryKey(Long id){
        return orderRefundMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<OrderRefund> query(OrderRefund orderRefund){
        return orderRefundMapper.query(orderRefund);
    }

    @Override
    public RestResult<PageResult<OrderRefundResponse>> queryPage(OrderRefundRequest orderRefundRequest) {
        //计算下标
        int startIndex = (orderRefundRequest.getStart() - 1) * orderRefundRequest.getLimit();
        List<OrderRefundResponse> list = orderRefundMapper.queryPage(startIndex, orderRefundRequest);
        long count = orderRefundMapper.queryPageCount(orderRefundRequest);
        PageResult<OrderRefundResponse> pageResult = new PageResult<>();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return RestResult.success(pageResult);
    }
}
